﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;

namespace FileManager_Client.PresentationLayer.NewUi
{
    public partial class RibbonForm1 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public RibbonForm1()
        {
            InitializeComponent();
            
           // LookAndFeel.SetSkinStyle("Wizard97");

            DevExpress.XtraEditors.Repository.RepositoryItemProgressBar test = new RepositoryItemProgressBar();
            gridView1.Columns["Test2"].ColumnEdit = test;
            DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit test2 = new RepositoryItemButtonEdit();
           // test2.NullText = "下载";
            DevExpress.XtraEditors.Repository.RepositoryItemImageEdit image = new RepositoryItemImageEdit();
            image.PictureAlignment = ContentAlignment.MiddleLeft;
            Image im1 = Image.FromFile(@"Folder_Icon\48x48\folder.png");
            image.Images = im1;
            //image.
            test2.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(test2_ButtonClick);
            gridView1.Columns["Test1"].ColumnEdit = test2;
            foreach (GridColumn column in gridView1.Columns)
            {
                column.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            }
            gridView1.RowHeight = 50;
            gridView1.ColumnPanelRowHeight = 40;
            //  gridView1.ShowLoadingPanel();
            //gridControl1.Height = 50;
            //     gridView1.ShowButtonMode = ShowButtonModeEnum.ShowAlways;
            gridControl1.Paint += gridControl1_Paint;
            gridView1.ScrollStyle = ScrollStyleFlags.LiveVertScroll;
            List<ListObj> listObjs = new List<ListObj>();
            // gridView1.OptionsView.ShowHorizontalLines = DevExpress.Utils.DefaultBoolean.False;
            gridView1.OptionsView.ShowVerticalLines = DevExpress.Utils.DefaultBoolean.False;
            gridView1.OptionsView.ShowPreviewRowLines = DevExpress.Utils.DefaultBoolean.False;
            for (int i = 0; i < 50; i++)
            {
                listObjs.Add(new ListObj
                {
                    Test2 = i + 5,
                    Test3 = i.ToString()//,
                    // Test1 = i.ToString()
                });
            }
            gridControl1.DataSource = listObjs;
            foreach (RibbonPage pag in ribbonControl.Pages)
            {
                foreach (RibbonPageGroup pagGroup in pag.Groups)
                {
                    bool VisibleAll = false;
                    foreach (BarItemLink itemLink in pagGroup.ItemLinks)
                    {
                        if (IsVisible(itemLink))
                        {
                            VisibleAll = true;
                            continue;
                        }
                    }

                    if (!VisibleAll)
                        pagGroup.Visible = VisibleAll;
                }

            }

        }

        private bool IsVisible(BarItemLink itemLink)
        {
            return (itemLink.Item.Visibility == BarItemVisibility.Always || itemLink.Item.Visibility == BarItemVisibility.OnlyInRuntime) && itemLink.Visible;
        }

        void gridControl1_Paint(object sender, PaintEventArgs e)
        {
            //GridViewInfo vi = gridView1.GetViewInfo() as GridViewInfo;
            //Point p1 = new Point(vi.ColumnsInfo[gridView1.Columns[0]].Bounds.Right - 1, vi.ViewRects.Rows.Y);
            //Point p2 = new Point(vi.ColumnsInfo[gridView1.Columns[0]].Bounds.Right - 1, vi.ViewRects.Rows.Bottom);
            //Pen p = new Pen(gridView1.PaintAppearance.HorzLine.BackColor);
            //e.Graphics.DrawLine(p, p1, p2);
        }

        void test2_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {

        }
    }

    //public class ListObj
    //{
    //    public string Test1 { get; set; }
    //    public int Test2 { get; set; }
    //    public string Test3 { get; set; }
    //}
}